//
//  PayClass.m
//  ELife
//
//  Created by fenglu on 11-7-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "PayClass.h"
#import "ELifeAppDelegate.h"
#import "GTMBase64.h"

@implementation PayClass
//-(void) getMyMailInfo;
@synthesize shopId;

-(id) init:(id<PayClassDeleage>)target payStyle:(PayStyle)style
{
    delegate = target;
    if ([super init]) {
        
    }
    myStyle = style;
    return self;
}

-(void) openShopingMallStyle
{
    [self getMyMailInfo];
}

-(void) getMyMailInfo
{
    
    NSString* userid = [GetMyData getUserId];
    if (userid != nil) {
        if (mailInfo == nil) {
            mailInfo = [[GetMailInfo alloc] init:self];
        }
        [mailInfo getMyMailAddress];
    }else
    {
        [delegate failedNoUserId];
    }
    
    
}

#pragma mark 余额
-(void) shopAccount_goodspay:(NSString*)mail_id
{
    ELifeAppDelegate* app = [ELifeAppDelegate App];
    NSMutableDictionary *param = [[NSMutableDictionary alloc]initWithCapacity:20];
    NSString* user_id = [GetMyData getUserId];
            
    [param setObject:@"account_goodspay" forKey:@"action"];
    [param setObject:user_id forKey:@"user_id"];
    [param setObject:mail_id forKey:@"mail_id"];
    [param setObject:@"111" forKey:@"goods_id"];
    [param setObject:@"" forKey:@"is_daijinquan"];
    [param setObject:@"EMS" forKey:@"mail_type"];
    [param setObject:@"0" forKey:@"mail_cost"];
    [param setObject:@"1" forKey:@"goods_number"];
    [param setObject:@"4000" forKey:@"money"];
    [param setObject:[[NSBundle mainBundle] localizedStringForKey:(@"ClientVersion") value:@"" table:nil] forKey:@"version"];
    NSString* urlRegister = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] localizedStringForKey:(@"BussinessHost") value:@"" table:nil], @"goods.php?"];
    
    NSDictionary* dic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSURL URLWithString:urlRegister], @"Account_goodspay:", nil] forKeys:[NSArray arrayWithObjects:@"url", @"requestMethod", nil]];

    [[app httpRequestPoint]openUrl:dic postParam:param target:self];
    
    [param release];
}

#pragma mark 银行直接支付
-(void) shopMvpos_goodspay:(NSString*)mail_id CardId:(NSString*)cardId
{
    ELifeAppDelegate* app = [ELifeAppDelegate App];
    NSMutableDictionary *param = [[NSMutableDictionary alloc]initWithCapacity:20];
    NSString* user_id = [GetMyData getUserId];
    
    [param setObject:@"mvpos_goodspay" forKey:@"action"];
    [param setObject:user_id forKey:@"user_id"];
    [param setObject:mail_id forKey:@"mail_id"];
    [param setObject:shopId forKey:@"goods_id"];
    [param setObject:@"" forKey:@"is_daijinquan"];
    [param setObject:@"EMS" forKey:@"mail_type"];
    [param setObject:@"0" forKey:@"mail_cost"];
    [param setObject:@"1" forKey:@"goods_number"];
    [param setObject:cardId forKey:@"card_num"];
    [param setObject:@"4000" forKey:@"money"];
    [param setObject:[[NSBundle mainBundle] localizedStringForKey:(@"ClientVersion") value:@"" table:nil] forKey:@"version"];
    NSString* urlRegister = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] localizedStringForKey:(@"UserHost") value:@"" table:nil], @"goods.php?"];
    
    NSDictionary* dic = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:[NSURL URLWithString:urlRegister], @"Mvpos_goodspay:", nil] forKeys:[NSArray arrayWithObjects:@"url", @"requestMethod", nil]];
    
    [[app httpRequestPoint]openUrl:dic postParam:param target:self];
    
    [param release];

}

#pragma mark 回调
-(void) NotMailAddress
{
    [delegate NotMailAddress];
}


-(void) getMailFinish:(NSArray*)temp
{
    [delegate getMailFinish:temp];
}

#pragma mark 付款回调
-(void) Account_goodspay:(NSData*)data
{
    NSMutableString* retStr = [[NSMutableString alloc]  initWithData:[GTMBase64 decodeData:data] encoding:NSUTF8StringEncoding];
    NSLog(@"%@", retStr);
    [retStr release];

}


-(void) Mvpos_goodspay:(NSData*)data
{
    NSMutableString* retStr = [[NSMutableString alloc]  initWithData:[GTMBase64 decodeData:data] encoding:NSUTF8StringEncoding];
    NSLog(@"%@", retStr);
    [retStr release];
}
@end
